#include <stdio.h>
#include <stdlib.h>

void print_pathway (int N, int L, int pathway[L][N])
{
	int i, j;

	printf ("c candidate pathway\n");
	for (i = 0; i < L; i++)
	{
		for (j = 0; j < N; j++)
		{
			printf ("%d ", pathway[i][j]);
		}
		printf ("\n");
	}
}

int main (int argc, char *argv[])
{
	FILE *fp;
	char buf[256];
	int i, j, N, L;

	N = atoi (argv[1]);
	L = atoi (argv[2]);

	int pathway[L][N];

	fp = fopen (argv[3], "r");
	while (fgets (buf, 256, fp))
	{
		for (i = 0; i < L; i++)
		{
			for (j = 0; j < N; j++)
			{
				fscanf (fp, "%d", &pathway[i][j]);
			}
			fgets (buf, 256, fp);
		}

		for (i = 0; i < N; i++)
		{
			for (j = 0; j < L - 4; j++)
			{
				if (pathway[j][i] == 0 && pathway[j + 1][i] == 0 && pathway[j + 2][i] == 0)
				{
					pathway[j + 1][i] = 1;
					print_pathway (N, L, pathway);
					pathway[j + 1][i] = 0;
				}
				else if (pathway[j][i] == 1 && pathway[j + 1][i] == 1 && pathway[j + 2][i] == 1)
				{
					pathway[j + 1][i] = 0;
					print_pathway (N, L, pathway);
					pathway[j + 1][i] = 1;
				}
			}
		}
	}
	fclose (fp);
}
